﻿using System.Collections.Generic;
using System.Linq;

namespace HQS.TokenInterpolation.Tokens
{
    [Token(Name = "sum")]
    public class Sum : AbstractToken
    {
        [TokenProperty("this", true)]
        public string This { get; protected set; }

        [TokenProperty("expression", true)]
        public string Expression { get; protected set; }

        [TokenProperty("format", false)]
        public string Format { get; set; }

        protected override TokenRuntimeValue OnAccept(IDataSourcesVisitor dataSourcesVisitor)
        {
            return dataSourcesVisitor.Visit(this);
        }

        public virtual double Aggregate(List<double> result)
        {
            return result.Sum();
        }
    }
}